package com.insurance.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdcardUtil;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.exceptions.ClientException;
import com.insurance.common.common.CommonResponseData;
import com.insurance.common.common.ResponseData;
import com.insurance.common.constant.ConstantFlag;
import com.insurance.common.constant.ConstantRedis;
import com.insurance.common.dto.*;
import com.insurance.common.enums.*;
import com.insurance.common.utils.JwtOperatorUtil;
import com.insurance.common.utils.NumberUtils;
import com.insurance.common.utils.SignUtil;
import com.insurance.constant.ConstantData;
import com.insurance.entity.*;
import com.insurance.service.*;
import com.insurance.utils.SendSmsUtils;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * 统一认证控制器
 *
 * @version 1.0
 * @date 2020/10/19
 **/
@Slf4j
@RestController
@RequestMapping("/authentication")
public class AuthenticationController {

    //region 注入类
    /**
     * 用户service
     */
    @Autowired
    private AuthenticationUserService authenticationUserService;

    /**
     * 企业service
     */
    @Autowired
    private AuthenticationEnterpriseService authenticationEnterpriseService;

    /**
     * 用户企业关系service
     */
    @Autowired
    private AuthenticationUserEnterpriseService authenticationUserEnterpriseService;

    /**
     * 认证信息service
     */
    @Autowired
    private AuthenticationService authenticationService;

    /**
     * 合作信息service
     */
    @Autowired
    private PartnerInfoService partnerInfoService;

    /**
     * 合作方登录日志service
     */
    @Autowired
    private PartnerLoginLogService partnerLoginLogService;

    /**
     * 合作方权限service
     */
    @Autowired
    private PartnerPermissionService partnerPermissionService;

    /**
     * 合作方权限service
     */
    @Autowired
    private PartnerService partnerService;

    @Autowired
    private Environment env;

    /**
     * redis客户端
     */
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 默认密码
     */
    private static final String defaultPassword = "111111";

    //endregion

    //region 获取合作方token

    /**
     * 获取合作方token
     *
     * @param accessTokenParamDto 请求参数
     * @param sign 签名
     * @return
     */
    @PostMapping("/getAccessToken")
    public CommonResponseData getAccessToken(@RequestBody AccessTokenParamDto accessTokenParamDto, @RequestHeader String sign){
        PartnerLoginLogEntity partnerLoginLogEntity = null;
        String appId = accessTokenParamDto.getAppId();
        String appSecret = accessTokenParamDto.getAppSecret();
        String timeStamp = accessTokenParamDto.getTimeStamp();
        try {
            if(StringUtils.isBlank(appId) || StringUtils.isBlank(appSecret) || StringUtils.isBlank(timeStamp)){
                log.error("【[{}]接口获取合作方token失败, 参数错误】", appId);
                return CommonResponseData.error(CommonProEnum.PARAMETER_ERROR);
            }
            partnerLoginLogEntity = new PartnerLoginLogEntity(appId, new Date(),
                    LoginStateEnum.LOGIN_SUCCESS.getCode(),
                    getLoginRequest(appId, appSecret, timeStamp, sign));
            //验签
            if(!SignUtil.verification(appId+appSecret+timeStamp, sign)){
                log.error("【[{}]接口登录失败, 验签错误】", appId);
                partnerLoginLogEntity.setResponseData("接口登录失败, 验签错误");
                saveLoginLog(partnerLoginLogEntity);
                return CommonResponseData.error(CommonProEnum.SIGN_ERROR);
            }
            //校验账号和密钥
            if(partnerInfoService.isValidate(appId, appSecret)){
                //通过appId获取合作对象并更新登录时间
                PartnerInfoEntity partnerInfoEntity = partnerInfoService.loginByAppId(appId);
                //获取权限集合
                List<String> permissionIdList = partnerService.getPermissionListByPartnerId(String.valueOf(partnerInfoEntity.getPartnerId()));
                List<String> permissionList = partnerPermissionService.getPermissionByIds(permissionIdList);
                Map<String, Object> partnerInfoMap = BeanUtil.beanToMap(new InsurancePartner(partnerInfoEntity, permissionList), false, false);
                String token = JwtOperatorUtil.generateToken(partnerInfoMap);
                log.info("【[{}]接口获取token成功：{}】", appId, token);
                ConstantData.tokenList.add(token);
                partnerLoginLogEntity.setResponseData(token);
                saveLoginLog(partnerLoginLogEntity);
                /**
                 * 日志和拦截器校验url以及后台管理和测试
                 */
                return CommonResponseData.success(CommonProEnum.GET_TOKEN_SUCCESS, token);
            }else{
                log.info("【[{}]接口获取token失败, 账号密码不正确, appId：{}, appSecret：{}】", appId, appSecret);
                partnerLoginLogEntity.setLoginState(LoginStateEnum.LOGIN_ERROR.getCode());
                partnerLoginLogEntity.setResponseData("接口获取token失败, 账号密码不正确");
                saveLoginLog(partnerLoginLogEntity);
                return CommonResponseData.success(CommonProEnum.GET_TOKEN_ERROR);
            }
        } catch (Exception e) {
            log.info("【[{}]接口获取token失败, appId：{}, appSecret：{}, 系统异常：{}】", appId, appSecret, e.getMessage());
            partnerLoginLogEntity.setLoginState(LoginStateEnum.LOGIN_ERROR.getCode());
            partnerLoginLogEntity.setResponseData("接口获取token失败, 系统异常");
            saveLoginLog(partnerLoginLogEntity);
            return CommonResponseData.success(CommonProEnum.SYSTEM_ERROR);
        }
    }
    //endregion

    //region 保存登录日志

    /**
     * 保存登录日志
     *
     * @param partnerLoginLogEntity 登录日志对象
     */
    public void saveLoginLog(PartnerLoginLogEntity partnerLoginLogEntity){
        try {
            partnerLoginLogService.save(partnerLoginLogEntity);
        } catch (Exception e) {
            log.error("【保存登录日志失败】", e);
        }
    }
    //endregion

    //region 获取登录请求数据

    /**
     * 获取登录请求数据
     *
     * @param appId 账号
     * @param appSecret 密码
     * @param timeStamp 时间戳
     * @param sign 签名
     * @return
     */
    public String getLoginRequest(String appId, String appSecret, String timeStamp, String sign){
        try {
            JSONObject json = new JSONObject();
            json.put("appId", appId);
            json.put("appSecret", appSecret);
            json.put("timeStamp", timeStamp);
            json.put("sign", sign);
            return json.toJSONString();
        } catch (Exception e) {
            log.error("【获取登录请求数据失败】", e);
            return "";
        }
    }
    //endregion

    //region 表单登录

    /**
     * 表单登录
     *
     * @param username 用户名
     * @param password 密码
     * @return
     */
    @PostMapping("/form/login")
    public CommonResponseData formLogin(HttpServletRequest request, @RequestParam String validateCode, @RequestParam String username,
                                  @RequestParam String password, @RequestParam Long randomCode){
        try {
            if(!ConstantData.validateCodeMap.containsKey(randomCode)){
                log.error("【[{}]登录失败, 验证码不存在】", username);
                return CommonResponseData.error(CommonProEnum.LOGIN_VALIDATE_ERROR);
            }
            if(!ConstantData.validateCodeMap.get(randomCode).equals(validateCode)){
                log.error("【[{}]登录失败, 验证码错误】", username);
                return CommonResponseData.error(CommonProEnum.LOGIN_VALIDATE_ERROR);
            }
            ConstantData.validateCodeMap.remove(randomCode);
            //通过用户名查询用户
            AuthenticationUserEntity user = authenticationUserService.findByUserName(username, "test");
            if(user == null){
                log.error("【[{}]登录失败, 用户不存在】", username);
                return CommonResponseData.error(CommonProEnum.USER_NOT_EXIT);
            }
            if(StringUtils.isBlank(user.getPassword()) || !password.equals(user.getPassword())){
                log.error("【[{}]登录失败, 用户名密码错误】", username);
                return CommonResponseData.error(CommonProEnum.LOGIN_INFO_ERROR);
            }
            Map<String, Object> userInfoMap = BeanUtil.beanToMap(new InsuranceUser(user), false, false);
            String userToken = JwtOperatorUtil.generateToken(userInfoMap);
            log.info("【[{}]登录成功：{}】", username, userToken);
            ConstantData.tokenList.add(userToken);
            return CommonResponseData.success(CommonProEnum.LOGIN_SUCCESS, userToken);
        } catch (Exception e) {
            log.error("【[{}]登录失败, 系统异常：{}】", username, e.getMessage());
            return CommonResponseData.error(CommonProEnum.LOGIN_INFO_ERROR);
        }
    }
    //endregion

    //region 接口登录

    /**
     * 接口登录
     *
     * @param userLoginParamDto 参数
     * @param sign 签名(两次MD5)
     * @return
     */
    @PostMapping("/userLogin")
    public CommonResponseData userLogin(HttpServletRequest request, @RequestBody UserLoginParamDto userLoginParamDto, @RequestHeader String sign) {
        String userName = userLoginParamDto.getUserName();
        String password = userLoginParamDto.getPassword();
        Long timeStamp = userLoginParamDto.getTimeStamp();
        try {
            if(StringUtils.isBlank(userName) || StringUtils.isBlank(password) || timeStamp == null){
                log.error("【[{}]接口登录失败, 参数错误】", userName);
                return CommonResponseData.error(CommonProEnum.PARAMETER_ERROR);
            }
            //验签
            if(!SignUtil.verification(userName+password+timeStamp, sign)){
                log.error("【[{}]接口登录失败, 验签错误】", userName);
                return CommonResponseData.error(CommonProEnum.SIGN_ERROR);
            }
            //通过用户名查询用户
            AuthenticationUserEntity user = authenticationUserService.findByUserName(userName, JwtOperatorUtil.getAppId(request));
            if(user == null){
                log.error("【[{}]接口登录失败, 用户不存在】", userName);
                return CommonResponseData.error(CommonProEnum.LOGIN_INFO_ERROR);
            }
            if(StringUtils.isBlank(user.getPassword()) || !password.equals(user.getPassword())){
                log.error("【[{}]接口登录失败, 用户名密码错误】", userName);
                return CommonResponseData.error(CommonProEnum.LOGIN_INFO_ERROR);
            }
            Map<String, Object> userInfoMap = BeanUtil.beanToMap(new InsuranceUser(user), false, false);
            String userToken = JwtOperatorUtil.generateToken(userInfoMap);
            log.info("【[{}]接口登录成功：{}】", userName, userToken);
            ConstantData.tokenList.add(userToken);
            return CommonResponseData.success(CommonProEnum.LOGIN_SUCCESS, userToken);
        } catch (Exception e) {
            log.error("【[{}]登录失败, 系统异常：{}】", userName, e.getMessage());
            return CommonResponseData.error(CommonProEnum.LOGIN_INFO_ERROR);
        }
    }
    //endregion

    //region 登出

    /**
     * 登出
     *
     * @param request
     * @return
     */
    @PostMapping("/form/logout")
    public CommonResponseData formLogout(HttpServletRequest request, @RequestHeader(value = "accessToken") String token){
        try {
            //获取token
            if(StringUtils.isBlank(token)){
                return CommonResponseData.error(CommonProEnum.TOKEN_ERROR);
            }
            try {
                if(JwtOperatorUtil.isTokenExpired(token)){
                    return CommonResponseData.error(CommonProEnum.TOKEN_ERROR);
                }
            } catch (Exception e) {
                return CommonResponseData.error(CommonProEnum.TOKEN_ERROR);
            }
            if(ConstantData.tokenList.contains(token)){
                ConstantData.tokenList.remove(token);
            }
            return CommonResponseData.success(CommonProEnum.LOGOUT_SUCCESS);
        } catch (Exception e) {
            log.error("【[{}]登出失败, 系统异常：{}】", token, e.getMessage());
            return CommonResponseData.success(CommonProEnum.LOGOUT_ERROR);
        }
    }
    //endregion

    //region 获取用户信息

    /**
     * 获取用户信息
     *
     * @return
     */
    @PostMapping("/getUserInfo")
    public CommonResponseData getUserInfo(@RequestHeader(value = "accessToken") String token, @RequestHeader(value = "userToken") String userToken){
        try {
            if(StringUtils.isBlank(userToken)){
                return CommonResponseData.error(CommonProEnum.TOKEN_ERROR);
            }
            //将token转换成用户信息
            Claims claims = JwtOperatorUtil.getClaimsFromToken(userToken);
            String userId = JwtOperatorUtil.getUserId(userToken);
            AuthenticationUserEntity user = authenticationUserService.getById(userId);
            if (user == null) {
                log.error("【获取用户信息失败, 通过主键查询数据不存在, userId：{}】", userId);
                return CommonResponseData.error(CommonProEnum.QUERY_ERROR_NODATA);
            }
            claims.put("state", user.getState());
            return CommonResponseData.success(claims);
        } catch (Exception e) {
            log.error("【获取用户信息失败：{}】", e);
            return CommonResponseData.error(CommonProEnum.TOKEN_ERROR);
        }
    }
    //endregion

    //region 完善企业信息

    /**
     * 完善企业信息
     *
     * @param token 合作方凭证
     * @param userToken 用户凭证
     * @param sign 用户凭证
     * @param authenticationEnterpriseEntity 企业信息
     * @return
     */
    /*@PostMapping("/perfectEnterpriseInfo")
    public CommonResponseData perfectEnterpriseInfo(@RequestHeader(value = "accessToken") String token,
                                                    @RequestHeader(value = "userToken") String userToken,
                                                    @RequestHeader String sign,
                                                    @RequestBody AuthenticationEnterpriseEntity authenticationEnterpriseEntity){
        try {
            //校验用户token有效性
            if(StringUtils.isBlank(userToken) || !JwtOperatorUtil.validateToken(userToken)){
                return CommonResponseData.error(CommonProEnum.USER_TOKEN_ERROR);
            }
            //校验表单
            *//*String checkResult = checkEnterpriseInfo(authenticationEnterpriseEntity);
            if(!ConstantFlag.TRUE_STR.equals(checkResult)){
                log.error("【完善企业信息失败：{}, 校验表单数据错误：{}】", authenticationEnterpriseEntity.getCertificateNo(), checkResult);
                return CommonResponseData.error(checkResult);
            }*//*
            //验签
            String appId = JwtOperatorUtil.getAppId(token);
            if(!SignUtil.verification(authenticationEnterpriseEntity.getEnterpriseName() + authenticationEnterpriseEntity.getCertificateNo() + appId, sign)){
                log.error("【[{}]接口登录失败, 验签错误】", authenticationEnterpriseEntity.getPhoneNumber());
                return CommonResponseData.error(CommonProEnum.SIGN_ERROR);
            }
            //获取用户Id
            String userId = JwtOperatorUtil.getUserId(userToken);
            //校验数据库中是否存在此企业
            boolean validateFlag = authenticationEnterpriseService.getByCardIdAndAppId(authenticationEnterpriseEntity.getCertificateNo(), JwtOperatorUtil.getAppId(token)) == null;
            //true表示校验通过
            if(validateFlag){
                authenticationEnterpriseEntity.setCreateTime(new Date());
                authenticationEnterpriseEntity.setCreatePersonId(userId);
                authenticationEnterpriseEntity.setCreatePersonName(JwtOperatorUtil.getUserName(userToken));
                authenticationEnterpriseEntity.setAppId(JwtOperatorUtil.getAppId(token));
                authenticationEnterpriseEntity.setState(ApprovalStateEnum.UN_PASS.getCode());
                boolean flag = authenticationService.saveAuthInfo(authenticationEnterpriseEntity);
                if(!flag){
                    log.error("【完善企业信息失败, 保存认证信息失败：{}】", authenticationEnterpriseEntity.getCertificateNo());
                    return CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
                }
                log.error("【完善企业信息成功：{}】", authenticationEnterpriseEntity.getCertificateNo());
                return CommonResponseData.success(String.valueOf(authenticationEnterpriseEntity.getId()));
            }else{
                log.error("【完善企业信息失败, 企业信息已存在：{}】", authenticationEnterpriseEntity.getCertificateNo());
                return CommonResponseData.error("存在已认证企业");
            }
        } catch (Exception e) {
            log.error("【完善企业信息失败：{}, 系统异常：{}】", authenticationEnterpriseEntity.getCertificateNo(), e);
            return CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
        }
    }*/
    //endregion

    //region 完善企业信息new

    /**
     * 完善企业信息new
     *
     * @param accessToken 接口凭证
     * @param userToken 用户凭证
     * @param sign 签名
     * @param authenticationEnterpriseEntity 企业信息
     * @return
     */
    @PostMapping("/perfectEnterpriseInfo")
    public CommonResponseData perfectEnterpriseInfo(@RequestHeader String accessToken,
                                                    @RequestHeader String userToken,
                                                    @RequestHeader String sign,
                                                    @RequestBody AuthenticationEnterpriseEntity authenticationEnterpriseEntity){
        try {
            //校验用户token有效性
            if(StringUtils.isBlank(userToken) || !JwtOperatorUtil.validateToken(userToken)){
                log.error("【完善企业信息失败, 用户凭证错误】");
                return CommonResponseData.error(CommonProEnum.USER_TOKEN_ERROR);
            }
            if(StringUtils.isBlank(authenticationEnterpriseEntity.getTimeStamp())){
                log.error("【完善企业信息失败, 时间戳不能为空】");
                return CommonResponseData.error(CommonProEnum.PARAMETER_ERROR.getCode(), "时间戳不能为空");
            }
            //获取appId
            String appId = JwtOperatorUtil.getAppId(accessToken);
            //获取用户Id
            String userId = JwtOperatorUtil.getUserId(userToken);
            if(!SignUtil.verification(authenticationEnterpriseEntity.getTimeStamp() + userId, sign)){
                log.error("【完善企业信息失败, 验签错误】", userId);
                return CommonResponseData.error(CommonProEnum.SIGN_ERROR);
            }
            AuthenticationUserEntity user = authenticationUserService.getById(userId);
            user.setState(UserStateEnum.REAL_NAME.getCode());
            user.setUserType(UserTypeEnum.ENTERPRISE.getCode());
            boolean userUpdateFlag = authenticationUserService.updateById(user);
            if(!userUpdateFlag){
                log.error("【完善企业信息失败, 修改用户类型失败】", userId);
                return CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
            }
            authenticationEnterpriseEntity.setCreateTime(new Date());
            authenticationEnterpriseEntity.setCreatePersonId(userId);
            authenticationEnterpriseEntity.setCreatePersonName(JwtOperatorUtil.getUserName(userToken));
            authenticationEnterpriseEntity.setAppId(appId);
            authenticationEnterpriseEntity.setState(ApprovalStateEnum.PASS.getCode());
            authenticationEnterpriseEntity.setDeleteFlag(String.valueOf(DeleteFlagEnum.UN_DELETE.getCode()));
            boolean flag = authenticationService.saveAuthInfo(authenticationEnterpriseEntity);
            if(!flag){
                log.error("【完善企业信息失败, 保存认证信息失败：{}】", userId);
                return CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
            }
            log.info("【完善企业信息成功：{}】", userId);
            return CommonResponseData.success(String.valueOf(authenticationEnterpriseEntity.getId()));
        } catch (Exception e) {
            log.error("【完善企业信息失败】", e);
            return CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
        }
    }
    //endregion

    //region 校验企业表单

    /**
     * 校验企业表单
     *
     * @param enterpriseEntity 企业对象
     * @return
     */
    public String checkEnterpriseInfo(AuthenticationEnterpriseEntity enterpriseEntity){
        if(enterpriseEntity == null){
            return "数据不能为空";
        }
        if(StringUtils.isBlank(enterpriseEntity.getEnterpriseName())){
            return "企业名称不能为空";
        }
        /*if(StringUtils.isBlank(enterpriseEntity.getCertificateNo())){
            return "企业证件号码不能为空";
        }
        if(StringUtils.isBlank(enterpriseEntity.getLegalPerson())){
            return "法人不能为空";
        }
        if(StringUtils.isBlank(enterpriseEntity.getLegalCardId())){
            return "法人证件号码不能为空";
        }
        if(StringUtils.isBlank(enterpriseEntity.getPhoneNumber())){
            return "电话号不能为空";
        }*/
        return ConstantFlag.TRUE_STR;
    }
    //endregion

    //region 用户注册

    /**
     * 用户注册
     *
     * @param authenticationUserEntity 用户对象
     * @return
     */
    @PostMapping("/register")
    public CommonResponseData register(HttpServletRequest request, @RequestBody AuthenticationUserEntity authenticationUserEntity, @RequestHeader String sign){
        String appId = "";
        try {
            appId = JwtOperatorUtil.getAppId(request);
            if(StringUtils.isBlank(appId)){
                log.error("【{}：注册用户失败, appId为空】");
                return CommonResponseData.error(CommonProEnum.TOKEN_TIME_OUT);
            }
            String checkResult = checkUserInfo(authenticationUserEntity);
            if(!ConstantFlag.TRUE_STR.equals(checkResult)){
                log.error("【{}：注册用户失败, {}】", appId, checkResult);
                return CommonResponseData.error(CommonProEnum.FORM_VALIDATE_ERROR.getCode(), checkResult);
            }
            if(!SignUtil.verification(authenticationUserEntity.getUserName()+authenticationUserEntity.getTimeStamp(), sign)){
                log.error("【{}：注册用户失败, 签名错误：{}】", appId, authenticationUserEntity.getUserName()+"|"+authenticationUserEntity.getTimeStamp()+"|"+sign);
                return CommonResponseData.error(CommonProEnum.SIGN_ERROR);
            }
            //通过用户手机号查询用户
            if(!StringUtils.isBlank(authenticationUserEntity.getPhoneNumber())){
                List<AuthenticationUserEntity> authenticationUserList = authenticationUserService.findListByPhoneNumber(authenticationUserEntity.getPhoneNumber(), appId);
                if(CollectionUtils.isNotEmpty(authenticationUserList)){
                    log.error("【{}：注册用户失败, 手机号已注册：{}】", appId, authenticationUserEntity.getPhoneNumber());
                   return CommonResponseData.error(CommonProEnum.PHONE_IS_EXIT);
                }
            }
            List<AuthenticationUserEntity> userList = authenticationUserService.findByUserNameList(authenticationUserEntity.getUserName(), appId);
            if(CollectionUtils.isNotEmpty(userList)){
               return CommonResponseData.error(CommonResponseEnum.ERROR.getCode(), "用户名重复");
            }
            //保存用户信息
            Date date = new Date();
            authenticationUserEntity.setCreateTime(date);
            authenticationUserEntity.setUpdateTime(date);
            authenticationUserEntity.setAppId(appId);
            //未实名
            authenticationUserEntity.setState(UserStateEnum.NOT_REAL_NAME.getCode());
            //此判断没有意义，只是为了方便查看意思
            if(!StringUtils.isBlank(authenticationUserEntity.getUserType()) && authenticationUserEntity.getUserType().equals(UserTypeEnum.ENTERPRISE.getCode())){
                authenticationUserEntity.setUserType(UserTypeEnum.ENTERPRISE.getCode());
            }else{
                authenticationUserEntity.setUserType(UserTypeEnum.PERSON.getCode());
            }
            //密码为空设置默认密码
            if(StringUtils.isBlank(authenticationUserEntity.getPassword())){
                authenticationUserEntity.setPassword(defaultPassword);
            }
            //保存用户
            boolean flag = authenticationUserService.save(authenticationUserEntity);
            if(flag){
                log.info("【{}：注册用户成功, 手机号：{}】", appId, authenticationUserEntity.getPhoneNumber());
            }else{
                log.error("【{}：注册用户失败, 数据库保存失败】", appId);
            }
            return flag ? CommonResponseData.success(CommonProEnum.OPERATION_SUCCESS) : CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
        } catch (Exception e) {
            log.error("【{}：注册用户失败, 系统异常：{}】", appId, e.getMessage());
            return CommonResponseData.error(CommonProEnum.SYSTEM_ERROR);
        }
    }
    //endregion

    //region 完善用户信息

    /**
     * 完善用户信息
     *
     * @param request 请求
     * @param authenticationUserEntity 用户对象
     * @return
     */
    @PostMapping("/perfectUserInfo")
    public CommonResponseData perfectUserInfo(HttpServletRequest request,
                                              @RequestHeader String accessToken,
                                              @RequestHeader String userToken,
                                              @RequestHeader String sign,
                                              @RequestBody AuthenticationUserEntity authenticationUserEntity){
        String appId = "";
        try {
            appId = JwtOperatorUtil.getAppId(request);
            //校验用户凭证有效性
            if(StringUtils.isBlank(userToken) || !JwtOperatorUtil.validateToken(userToken)){
                log.error("【{}：完善用户信息失败, 用户凭证错误】", appId);
                return CommonResponseData.error(CommonProEnum.USER_TOKEN_ERROR);
            }
            if(StringUtils.isBlank(appId)){
                log.error("【{}：完善用户信息失败, appId为空】", appId);
                return CommonResponseData.error(CommonProEnum.TOKEN_TIME_OUT);
            }
            String checkResult = checkUserPerInfo(authenticationUserEntity);
            if(!ConstantFlag.TRUE_STR.equals(checkResult)){
                log.error("【{}：完善用户失败, {}】", appId, checkResult);
                return CommonResponseData.error(CommonProEnum.FORM_VALIDATE_ERROR.getCode(), checkResult);
            }
            if(authenticationUserEntity.getCertificateType().equals(UserCardTypeEnum.SHEN_FEN_ZHENG.getCode())){
                if(!IdcardUtil.isValidCard(authenticationUserEntity.getCertificateNo())){
                    log.error("【{}：完善用户失败, 身份证号不正确】", appId);
                    return CommonResponseData.error(CommonResponseEnum.ERROR.getCode(), "身份证号不正确");
                }
            }
            /*if(!StringUtils.isBlank(authenticationUserEntity.getPhoneNumber())){
                List<AuthenticationUserEntity> userList = authenticationUserService.findListByPhoneNumber(authenticationUserEntity.getPhoneNumber(), appId);
                if(CollectionUtils.isNotEmpty(userList)){
                    log.error("【{}：完善用户失败, 手机号已经被注册：{}】", appId, authenticationUserEntity.getPhoneNumber());
                    return CommonResponseData.error(CommonProEnum.PHONE_IS_EXIT);
                }
            }*/
            String signStr = authenticationUserEntity.getName() +
                    authenticationUserEntity.getCertificateType() +
                    authenticationUserEntity.getCertificateNo() +
                    authenticationUserEntity.getPhoneNumber();
            if(!SignUtil.verification(signStr, sign)){
                log.error("【{}：完善用户失败, 签名错误：{}】", appId, signStr+"|"+sign);
                return CommonResponseData.error(CommonProEnum.SIGN_ERROR);
            }
            //通过手机号查询用户
            String userId = JwtOperatorUtil.getUserId(userToken);
            //通过主键查询用户
            AuthenticationUserEntity user = authenticationUserService.getById(userId);
            if(user == null){
                log.error("【{}：完善用户信息失败, 用户不存在】", userId);
                return CommonResponseData.error(CommonResponseEnum.ERROR.getCode(), "用户不存在");
            }
            if(StringUtils.isBlank(user.getAppId()) || !appId.equals(user.getAppId())){
                log.error("【{}：完善用户信息失败, 用户来源不一致, 用户appId：{}】", appId, user.getAppId());
                return CommonResponseData.error(CommonResponseEnum.ERROR.getCode(), "用户来源不一致");
            }
            if(StringUtils.isNotBlank(user.getState()) && UserStateEnum.REAL_NAME.getCode().equals(user.getState())){
                log.error("【{}：完善用户信息失败, 不能重复完善信息】", userId);
               return CommonResponseData.error(CommonResponseEnum.ERROR.getCode(), "不能重复完善信息");
            }
            user.setCertificateType(authenticationUserEntity.getCertificateType());
            user.setCertificateNo(authenticationUserEntity.getCertificateNo());
            if(!StringUtils.isBlank(authenticationUserEntity.getPhoneNumber())){
                user.setPhoneNumber(authenticationUserEntity.getPhoneNumber());
            }
            user.setRealName(authenticationUserEntity.getName());
            user.setUpdateTime(new Date());
            user.setState(UserStateEnum.REAL_NAME.getCode());
            boolean flag = authenticationUserService.updateById(user);
            if(flag){
                log.info("【{}：完善用户信息成功, 用户：{}, 手机号：{}】", appId, user.getRealName(), user.getPhoneNumber());
            }else{
                log.error("【{}：完善用户信息失败, 保存数据库失败】", appId);
            }
            return flag ? CommonResponseData.success(CommonProEnum.OPERATION_SUCCESS) : CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
        } catch (Exception e) {
            log.error("【{}：完善用户信息失败, 系统异常：{}】", appId, e.getMessage());
            return CommonResponseData.error(CommonProEnum.SYSTEM_ERROR);
        }
    }
    //endregion

    //region 校验用户信息

    /**
     * 校验用户信息
     *
     * @param authenticationUserEntity 用户对象
     * @return
     */
    public String checkUserInfo(AuthenticationUserEntity authenticationUserEntity){
        /*if(StringUtils.isBlank(authenticationUserEntity.getPhoneNumber())){
            return "手机号不能为空";
        }*/
        /*if(StringUtils.isBlank(authenticationUserEntity.getRealName())){
            return "真实姓名不能为空";
        }*/
        if(StringUtils.isBlank(authenticationUserEntity.getUserName())){
            return "用户名不能为空";
        }
        if(StringUtils.isBlank(authenticationUserEntity.getPassword())){
            return "密码不能为空";
        }
        if(StringUtils.isBlank(authenticationUserEntity.getUserType())){
            return "用户类型不能为空";
        }
        if(StringUtils.isBlank(authenticationUserEntity.getTimeStamp())){
            return "时间戳不能为空";
        }
        return ConstantFlag.TRUE_STR;
    }
    //endregion

    //region 校验用户完善信息

    /**
     * 校验用户完善信息
     *
     * @param authenticationUserEntity 用户对象
     * @return
     */
    public String checkUserPerInfo(AuthenticationUserEntity authenticationUserEntity){
        if(StringUtils.isBlank(authenticationUserEntity.getPhoneNumber())){
            return "手机号不能为空";
        }
        if(StringUtils.isBlank(authenticationUserEntity.getCertificateType())){
            return "证件类型不能为空";
        }
        if(StringUtils.isBlank(authenticationUserEntity.getCertificateNo())){
            return "证件号码不能为空";
        }
        if(StringUtils.isBlank(authenticationUserEntity.getName())){
            return "真实姓名不能为空";
        }
        return ConstantFlag.TRUE_STR;
    }
    //endregion

    //region 通过用户token查询关联企业

    /**
     * 通过用户token查询关联企业
     *
     * @param token
     * @param userToken
     * @return
     */
    @PostMapping("/queryEnterpriseList")
    public CommonResponseData<List<AuthenticationEnterpriseDto>> queryEnterpriseList(@RequestHeader(value = "accessToken") String token, @RequestHeader String userToken){
        if(!JwtOperatorUtil.validateToken(userToken)){
            return CommonResponseData.error(CommonProEnum.USER_TOKEN_ERROR);
        }
        List<AuthenticationEnterpriseDto> enterpriseDtoList = new ArrayList<AuthenticationEnterpriseDto>();
        List<String> idList = new ArrayList<String>();
        List<String> enterpriseIdList = authenticationUserEnterpriseService.queryEnterpriseIdListByUserId(JwtOperatorUtil.getUserId(userToken));
        enterpriseIdList.forEach(id -> {
            idList.add(id);
        });
        List<AuthenticationEnterpriseEntity> enterpriseEntityList = authenticationEnterpriseService.queryEnterpriseListByIds(idList);
        if(CollectionUtils.isEmpty(enterpriseEntityList)){
            return CommonResponseData.success(enterpriseDtoList);
        }
        enterpriseEntityList.forEach(authenticationEnterpriseEntity -> {
            AuthenticationEnterpriseDto authenticationEnterpriseDto = new AuthenticationEnterpriseDto();
            BeanUtils.copyProperties(authenticationEnterpriseEntity, authenticationEnterpriseDto);
            enterpriseDtoList.add(authenticationEnterpriseDto);
        });
        return CommonResponseData.success(enterpriseDtoList);
    }
    //endregion

    //region 校验企业是否认证

    /**
     * 校验企业是否认证
     *
     * @param token 凭证
     * @param cardId 统一信用代码
     * @return
     */
    @PostMapping("/validateAuthentication")
    public CommonResponseData validateAuthentication(@RequestHeader(value = "accessToken") String token, @RequestBody String cardId){
        try {
            AuthenticationEnterpriseEntity enterpriseEntity = authenticationEnterpriseService.getByCardIdAndAppId(cardId, JwtOperatorUtil.getAppId(token));
            if(enterpriseEntity == null){
                return CommonResponseData.error(CommonProEnum.UN_AUTHENTICATION);
            }
            /*if(!StringUtils.isBlank(enterpriseEntity.getState()) && !ApprovalStateEnum.PASS.getCode().equals(enterpriseEntity.getState())){
                return ResponseData.error(CommonEnum.UN_PASS);
            }*/
            AuthenticationEnterpriseDto authenticationEnterpriseDto = new AuthenticationEnterpriseDto();
            BeanUtils.copyProperties(enterpriseEntity, authenticationEnterpriseDto);
            return CommonResponseData.success(CommonProEnum.AUTHENTICATION, authenticationEnterpriseDto);
        } catch (Exception e) {
            log.error("【校验企业是否认证失败, 系统异常】", e);
            return CommonResponseData.error(CommonProEnum.SYSTEM_ERROR);
        }
    }
    //endregion

    //region 修改企业信息

    /**
     * 修改企业信息
     *
     * @param token 合作方凭证
     * @param userToken 用户凭证
     * @param authenticationEnterpriseEntity 企业信息
     * @return
     */
    @PostMapping("/editEnterpriseInfo")
    public CommonResponseData editEnterpriseInfo(@RequestHeader(value = "accessToken") String token,
                                           @RequestHeader(value = "userToken") String userToken,
                                           AuthenticationEnterpriseEntity authenticationEnterpriseEntity){
        try {
            //校验用户token有效性
            if(StringUtils.isBlank(userToken) || !JwtOperatorUtil.validateToken(userToken)){
                return CommonResponseData.error(CommonProEnum.USER_TOKEN_ERROR);
            }
            if(authenticationEnterpriseEntity.getId() == null){
                log.error("【修改企业信息失败, 企业id为空】");
                return CommonResponseData.error(CommonProEnum.QUERY_ERROR_NODATA);
            }
            //校验表单
            String checkResult = checkEnterpriseInfo(authenticationEnterpriseEntity);
            if(!ConstantFlag.TRUE_STR.equals(checkResult)){
                log.error("【修改企业信息失败：{}, 校验表单数据错误：{}】", authenticationEnterpriseEntity.getCertificateNo(), checkResult);
                return CommonResponseData.error(CommonProEnum.FORM_VALIDATE_ERROR.getCode(), checkResult);
            }
            //校验数据库中是否存在此企业
            AuthenticationEnterpriseEntity aee = authenticationEnterpriseService.getByCardIdAndAppId(authenticationEnterpriseEntity.getCertificateNo(), JwtOperatorUtil.getAppId(token));
            if(aee != null && !aee.getId().equals(authenticationEnterpriseEntity.getId())){
                log.error("【修改企业信息失败, 企业信息已存在：{}】", authenticationEnterpriseEntity.getCertificateNo());
                return CommonResponseData.error(CommonResponseEnum.ERROR.getCode(), "存在已认证企业");
            }
            //true表示校验通过
            authenticationEnterpriseEntity.setUpdateTime(new Date());
            authenticationEnterpriseEntity.setUpdatePersonId(JwtOperatorUtil.getUserId(userToken));
            authenticationEnterpriseEntity.setUpdatePersonName(JwtOperatorUtil.getUserName(userToken));
            boolean flag = authenticationEnterpriseService.updateById(authenticationEnterpriseEntity);
            if(!flag){
                log.error("【修改企业信息失败, 数据库修改失败：{}】", authenticationEnterpriseEntity.getId());
                return CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
            }
            log.error("【修改企业信息成功：{}】", authenticationEnterpriseEntity.getId());
            return CommonResponseData.success(String.valueOf(authenticationEnterpriseEntity.getId()));

        } catch (Exception e) {
            log.error("【修改企业信息失败：{}, 系统异常：{}】", authenticationEnterpriseEntity.getId(), e);
            return CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
        }
    }
    //endregion

    //region 删除企业信息

    /**
     * 删除企业信息
     *
     * @param token 合作方凭证
     * @param userToken 用户凭证
     * @param id 主键
     * @return
     */
    @PostMapping("/removeEnterpriseInfo")
    public CommonResponseData removeEnterpriseInfo(@RequestHeader(value = "accessToken") String token,
                                             @RequestHeader(value = "userToken") String userToken,
                                             @RequestParam Long id){
        try {
            //校验用户token有效性
            if(StringUtils.isBlank(userToken) || !JwtOperatorUtil.validateToken(userToken)){
                return CommonResponseData.error(CommonProEnum.USER_TOKEN_ERROR);
            }
            AuthenticationEnterpriseEntity authenticationEnterpriseEntity = authenticationEnterpriseService.getById(id);
            authenticationEnterpriseEntity.setDeleteFlag(String.valueOf(DeleteFlagEnum.DELETE.getCode()));
            authenticationEnterpriseEntity.setDeleteTime(new Date());
            authenticationEnterpriseEntity.setDeletePersonId(JwtOperatorUtil.getUserId(userToken));
            authenticationEnterpriseEntity.setDeletePersonName(JwtOperatorUtil.getUserName(userToken));
            boolean flag = authenticationEnterpriseService.updateById(authenticationEnterpriseEntity);
            return flag ? CommonResponseData.success(authenticationEnterpriseEntity.getId()) : CommonResponseData.error(CommonProEnum.DELETE_ERROR);
        } catch (Exception e) {
            log.error("【删除企业信息失败, 系统异常】", e);
            return CommonResponseData.error(CommonProEnum.SYSTEM_ERROR);
        }
    }
    //endregion

    //region 重置密码

    /**
     * 重置密码
     *
     * @param token 凭证
     * @param userToken 用户凭证
     * @param password 旧密码
     * @param newPassword 新密码
     * @return
     */
    @PostMapping("/resetPassword")
    public CommonResponseData resetPassword(@RequestHeader(value = "accessToken") String token, @RequestHeader String userToken,
                                        @RequestParam String password, @RequestParam String newPassword){
        try {
            //校验用户token有效性
            if(StringUtils.isBlank(userToken) || !JwtOperatorUtil.validateToken(userToken)){
                log.error("【重置密码失败, 用户凭证失效】");
                return CommonResponseData.error(CommonProEnum.USER_TOKEN_ERROR);
            }
            String userId = JwtOperatorUtil.getUserId(userToken);
            AuthenticationUserEntity userEntity = authenticationUserService.getById(userId);
            if(userEntity == null){
                log.error("【重置密码失败, 用户不存在】");
                return CommonResponseData.error(CommonProEnum.QUERY_ERROR_NODATA);
            }
            if(!password.equals(userEntity.getPassword())){
                log.error("【重置密码失败, 旧密码不匹配】");
                return CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
            }
            userEntity.setPassword(newPassword);
            userEntity.setUpdateTime(new Date());
            boolean flag = authenticationUserService.updateById(userEntity);
            if(flag){
                log.info("【重置密码成功, 用户Id：{}】", userId);
            }
            return flag ? CommonResponseData.success(CommonProEnum.OPERATION_SUCCESS) : CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
        } catch (Exception e) {
            log.error("【重置密码失败, 系统异常】", e);
            return CommonResponseData.error(CommonProEnum.SYSTEM_ERROR);
        }
    }
    //endregion

    //region 找回密码

    /**
     * 找回密码
     *
     * @param token 凭证
     * @param retrievePasswordParamDto 参数
     * @return
     */
    @PostMapping("/retrievePassword")
    public CommonResponseData retrievePassword(@RequestHeader(value = "accessToken") String token, @RequestBody RetrievePasswordParamDto retrievePasswordParamDto){
        String phone = retrievePasswordParamDto.getUserName();
        String password = retrievePasswordParamDto.getPassword();
        try {
            if(StringUtils.isBlank(phone) || StringUtils.isBlank(password)){
                log.error("【[{}]接口找回密码失败, 参数错误】", phone);
                return CommonResponseData.error(CommonProEnum.PARAMETER_ERROR);
            }
            AuthenticationUserEntity userEntity = authenticationUserService.findByPhoneNumber(phone, JwtOperatorUtil.getAppId(token));
            if(userEntity == null){
                log.error("【找回密码失败, 用户不存在】");
                return CommonResponseData.error(CommonProEnum.QUERY_ERROR_NODATA);
            }
            userEntity.setPassword(password);
            userEntity.setUpdateTime(new Date());
            boolean flag = authenticationUserService.updateById(userEntity);
            if(flag){
                log.info("【找回密码成功, 用户Id：{}】", userEntity.getId());
            }
            return flag ? CommonResponseData.success(CommonProEnum.OPERATION_SUCCESS) : CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
        } catch (Exception e) {
            log.error("【找回密码失败, 系统异常】", e);
            return CommonResponseData.error(CommonProEnum.SYSTEM_ERROR);
        }
    }
    //endregion

    //region 发送信息

    /**
     * 发送信息
     *
     * @param accessToken 接口凭证
     * @param sign 签名
     * @param sendMessageDto 请求参数
     * @return
     */
    @PostMapping("/sendMessage")
    @ResponseBody
    public CommonResponseData sendMessage(@RequestHeader String accessToken, @RequestHeader String sign, @RequestBody SendMessageDto sendMessageDto){
        try {
            if(StringUtils.isBlank(sendMessageDto.getPhoneNumber())){
                log.error("【发送信息失败, 手机号不能为空】");
                return CommonResponseData.error(CommonProEnum.PARAMETER_ERROR, "手机号不能为空");
            }
            if(!SignUtil.verification(sendMessageDto.getPhoneNumber(), sign)){
                log.error("【{}：发送信息失败, 签名失败】", sendMessageDto.getPhoneNumber());
                return CommonResponseData.error(CommonProEnum.SIGN_ERROR);
            }
            /*if(stringRedisTemplate.hasKey(sendMessageDto.getPhone())){
                log.error("【{}：发送信息失败, 操作过于频繁】", sendMessageDto.getPhone());
                return CommonResponseData.error(CommonProEnum.OPERATION_FREQUENCY);
            }*/
            String verificationCode = NumberUtils.randomNumber(6);
            String templateParam = "{'code':'"+verificationCode+"'}";
            //todo
//            String signName = env.getProperty("");
            String appId = JwtOperatorUtil.getAppId(accessToken);
            //获取阿里云签名
            String signName = MessageEnums.MessageSignEnum.getMessage(appId);
            if(StringUtils.isBlank(signName)){
                log.error("【{}：发送信息失败, appId配置签名不存在】", appId);
                return CommonResponseData.error(CommonProEnum.PARAMETER_ERROR.getCode(), "appId配置签名不存在");
            }
            //获取模板编码
            String templateCode = MessageEnums.MessageTemplateEnum.getMessage(appId);
            if(StringUtils.isBlank(templateCode)){
                log.error("【{}：发送信息失败, appId配置模板编码不存在】", appId);
                return CommonResponseData.error(CommonProEnum.PARAMETER_ERROR.getCode(), "appId配置模板编码不存在");
            }
            SendSmsUtils.send(sendMessageDto.getPhoneNumber(), signName, templateCode, templateParam);
            stringRedisTemplate.opsForValue().set(ConstantRedis.USER_MSG_PREFIX+sendMessageDto.getPhoneNumber(), verificationCode, 300, TimeUnit.SECONDS);
            log.info("【{}：发送信息成功, 验证码：{}】", sendMessageDto.getPhoneNumber(), verificationCode);
            return CommonResponseData.success(CommonProEnum.OPERATION_SUCCESS);
        } catch (Exception e) {
            log.error("【{}：发送信息失败, 系统异常】", sendMessageDto.getPhoneNumber(), e);
            return CommonResponseData.error(CommonProEnum.OPERATION_ERROR);
        }
    }
    //endregion

    //region 校验验证码

    /**
     * 校验验证码
     *
     * @param accessToken 接口凭证
     * @param sign 签名
     * @param sendMessageDto 请求参数
     * @return
     */
    @PostMapping("/validateCode")
    @ResponseBody
    public CommonResponseData validateCode(@RequestHeader String accessToken, @RequestHeader String sign, @RequestBody SendMessageDto sendMessageDto){
        try {
            if(StringUtils.isBlank(sendMessageDto.getPhoneNumber())){
                log.error("【校验验证码失败, 手机号不能为空】");
                return CommonResponseData.error(CommonProEnum.PARAMETER_ERROR, "手机号不能为空");
            }
            if(StringUtils.isBlank(sendMessageDto.getCode())){
                log.error("【校验验证码失败, 验证码不能为空】");
                return CommonResponseData.error(CommonProEnum.PARAMETER_ERROR, "验证码不能为空");
            }
            if(!SignUtil.verification(sendMessageDto.getPhoneNumber()+sendMessageDto.getCode(), sign)){
                log.error("【{}：校验验证码失败, 签名失败】", sendMessageDto.getPhoneNumber());
                return CommonResponseData.error(CommonProEnum.SIGN_ERROR);
            }
            if(!stringRedisTemplate.hasKey(ConstantRedis.USER_MSG_PREFIX+sendMessageDto.getPhoneNumber())){
                log.error("【{}：校验验证码失败, 验证码不存在】", sendMessageDto.getPhoneNumber());
                return CommonResponseData.error(CommonProEnum.MESSAGE_INFO_ERROR);
            }
            //校验验证码
            String code = stringRedisTemplate.opsForValue().get(ConstantRedis.USER_MSG_PREFIX+sendMessageDto.getPhoneNumber());
            if(!sendMessageDto.getCode().equals(code)){
                log.error("【{}：校验验证码失败, 验证码错误, {} -> {}】", sendMessageDto.getPhoneNumber(), code, sendMessageDto.getCode());
                return CommonResponseData.error(CommonProEnum.LOGIN_VALIDATE_ERROR);
            }
            log.info("【{}：验证码校验成功, 验证码：{}】", sendMessageDto.getPhoneNumber(), code);
            try {
                Boolean flag = stringRedisTemplate.delete(ConstantRedis.USER_MSG_PREFIX + sendMessageDto.getPhoneNumber());
                log.error("【验证码校验成功, 删除key失败：{}】", ConstantRedis.USER_MSG_PREFIX+sendMessageDto.getPhoneNumber());
            } catch (Exception e) {
                log.error("【验证码校验成功, 删除key异常：{}】", ConstantRedis.USER_MSG_PREFIX+sendMessageDto.getPhoneNumber());
            }
            return CommonResponseData.success(CommonProEnum.OPERATION_SUCCESS);
        } catch (Exception e) {
            log.error("【{}：校验验证码失败, 系统异常】", sendMessageDto.getPhoneNumber(), e);
            return CommonResponseData.error(CommonProEnum.SYSTEM_ERROR);
        }
    }
    //endregion

    //region 查询企业数据

    /**
     * 查询企业数据
     *
     * @param enterpriseQueryDto 查询条件
     * @return
     */
    @PostMapping("/queryEnterprise")
    @ResponseBody
    public CommonResponseData queryEnterprise(@RequestBody EnterpriseQueryDto enterpriseQueryDto){
        try {
            AuthenticationEnterpriseEntity authenticationEnterprise = new AuthenticationEnterpriseEntity();
            BeanUtils.copyProperties(enterpriseQueryDto, authenticationEnterprise);
            List<AuthenticationEnterpriseEntity> enterpriseList = authenticationEnterpriseService.queryEnterprise(authenticationEnterprise);
            return CommonResponseData.success(CommonProEnum.QUERY_SUCCESS, enterpriseList);
        } catch (Exception e) {
            log.error("【查询企业数据失败, 系统异常】", e);
            return CommonResponseData.error(CommonProEnum.SYSTEM_ERROR);
        }
    }
    //endregion




    /*public static void main(String[] args) {
        String password = "123456";
        String userPassword = "$2a$10$lBa6qEqoS7vy6jF53Z9LVeCvuU4ClteghAwSvWBfWbqpaaF0zlCeS";
        PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        System.out.println(passwordEncoder.matches(password, userPassword));
    }*/

    /*public static void main(String[] args) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", "1");
        map.put("userName", "张三");
        String token = JwtOperatorUtil.generateToken(map);
        System.out.println(token);
//        String token = "eyJhbGciOiJIUzI1NiJ9.eyJwYXJ0bmVyTmFtZSI6Iua1i-ivleeUqOaItyIsInBhcnRuZXJDb2RlIjoidGVzdCIsImFwcElkIjoidGVzdCIsInBlcm1pc3Npb24iOlsiL2F1dGhlbnRpY2F0aW9uL2dldFVzZXJJbmZvIiwiL3Byb3Bvc2FsL2dldFByb3Bvc2FsRGV0YWlsIiwiL3Byb3Bvc2FsL2NoYW5nZVByb3Bvc2FsU3RhdGUiLCIvb3JkZXIvY2hhbmdlT3JkZXJTdGF0ZSIsIi9hdXRoZW50aWNhdGlvbi92YWxpZGF0ZUF1dGhlbnRpY2F0aW9uIiwiL29yZGVyL3JlbW92ZU9yZGVyIiwiL3Byb3Bvc2FsL3JlbW92ZVByb3Bvc2FsIiwiL3Byb3Bvc2FsL2VkaXRQcm9wb3NhbCIsIi9vcmRlci9lZGl0T3JkZXIiLCIvYXV0aGVudGljYXRpb24vcmVzZXRQYXNzd29yZFxuIiwiL2F1dGhlbnRpY2F0aW9uL3JldHJpZXZlUGFzc3dvcmRcbiIsIi9hdXRoZW50aWNhdGlvbi9wZXJmZWN0RW50ZXJwcmlzZUluZm8iLCIvcHJvZHVjdC9nZXRQcm9kdWN0SW5mb0J5Q29kZSIsIi9wcm9kdWN0L3F1ZXJ5UHJvZHVjdENhc2VCeUNvZGUiLCIvYXV0aGVudGljYXRpb24vaW50ZXJmYWNlL2xvZ2luIiwiL2F1dGhlbnRpY2F0aW9uL2ludGVyZmFjZS9yZWdpc3RlciIsIi9vcmRlci9xdWVyeU9yZGVyUGFnZSIsIi9wcm9wb3NhbC9xdWVyeVByb3Bvc2FsUGFnZSIsIi9vcmRlci9zYXZlT3JkZXIiLCIvcHJvcG9zYWwvc2F2ZVByb3Bvc2FsIiwiL29yZGVyL2dldE9yZGVyRGV0YWlsIl0sImlhdCI6MTYzMTkzMzY4MiwiZXhwIjoxNjMxOTQwODgyfQ.2T6J3UV6bTC5RdrUVXiV0ZSPmuUkKguFXco0Xjk3T6Q";
        Boolean flag = JwtOperatorUtil.isTokenExpired(token);
        Date expirationDateFromToken = JwtOperatorUtil.getExpirationDateFromToken(token);
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(expirationDateFromToken));
        System.out.println(flag);
    }*/


}
